<?php
/**
 * Created by PhpStorm.
 * User: Leonly
 * Date: 2015/9/22 0022
 * Time: 13:54
 */

class page_configAction extends backendAction {
    const config_name = 'page_default';

    public function index() {
        $config = M('config')->where('name="' . self::config_name . '"')->find();
        if($config) {
            $content = json_decode($config['content']);
            $this->assign('id', $config['id']);
            $this->assign('config', $content);
        }

        $this->display();
    }

    /**
     * 搜素提示
     */
    public function config() {

        $name = isset($_GET['name']) ? $_GET['name'] : 'searchTip';

        if(IS_POST) {
            $id = $_POST['id'];
            unset($_POST['id']);

            if(empty($id)) {
                M('config')->add($_POST);
            } else {
                unset($_POST['name']);
                M('config')->where('id=' . $id)->save($_POST);
            }
        }

        $config = M('config')->where('name="' . $name . '"')->find();
        $this->assign('config', $config);
        $this->assign('name', $name);
        $this->display($name);
    }
}
